<template>
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox">
                <div class="ibox-title">
                <h5>Patch详情</h5> 
                </div>
                <div class="ibox-content">
                    <el-table
                        :data="tableData"
                        style="width: 100%">
                        <el-table-column prop="updatetime" label="日期" min-width="100" fixed></el-table-column>
                        <el-table-column prop="number" min-width="" label="提交单号"></el-table-column>
                        <el-table-column prop="subject" min-width="300" label="标题"></el-table-column>
                        <el-table-column prop="branch" min-width="150" label="分支"></el-table-column>
                        <el-table-column prop="component" min-width="130" label="模块名称"></el-table-column>
                        <el-table-column prop="owner" min-width="100" label="所有者"></el-table-column>
                        <el-table-column prop="line_insert" min-width="" label="代码新增"></el-table-column>
                        <el-table-column prop="line_delete" min-width="" label="代码删除"></el-table-column>
                        <el-table-column prop="inline_comments" min-width="" label="行内注释"></el-table-column>
                        <el-table-column fixed="right" label="操作" width="100">
                            <template slot-scope="sub">
                                <el-button type="text" size="small" @click="goto_url_blank(sub.row)">查看详情</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <el-pagination
                        style="padding-top: 10px;"
                        background
                        @current-change="handleCurrentChange"
                        :current-page="currentPage"
                        layout="total, prev, pager, next, jumper"
                        :total="total">
                    </el-pagination>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
export default {
    props: {
        date: String,
        filter1: String,
        filter2: String
    },
    data() {
        return {
            project: '',
            currentPage: 1,
            total: 0,
            tableData: []
        }
    },
    methods: {
        getGerritInfo: function(project, time, branch, component, page) {
            var source = process.env.VUE_APP_KANBAN_HOST + '/api/qa/gethighlight?project=';
            source = source+project+'&time='+time+'&branch='+branch+'&component='+component+'&page='+page;
            this.$axios.get(source)
                .then((response) => {
                    if (response.status == 200) {
                        this.tableData = response.data.highlight;
                        this.total = response.data.count;
                    }
                })
                .catch(function(err) {
                    // eslint-disable-next-line
                    console.log(err);
                });
        },
        getData: function(page) {
            var branch = this.filter1;
            var component = this.filter2;
            var time = '';
            if (this.date == 'nullString') {
            
            } else if (this.date.length == 10) {
                time = this.date + ',' + this.date;
            } else {
                time = this.date;
            }
            this.getGerritInfo(this.project,time,branch,component,page);
        },
        handleCurrentChange(val) {
            console.log(`当前页: ${val}`);
            this.currentPage = val;
            this.getData(this.currentPage);
        },
        goto_url_blank(row) {
            var url = row.gerrit_url;            
            window.open(url, "_blank");
        },
    },
    created() {
        this.project = this.$route.params.pmsProjectId;
    },
    mounted() {
        this.getData(this.currentPage);
    }
}
</script>